package main

import "fmt"

type ListNode struct {
	Val  int
	Next *ListNode
}

//双指针:0ms 100%，2.1MB 61%
func getKthFromEnd(head *ListNode, k int) *ListNode {
	rHead := head
	for i := 1; i < k; i++ {
		rHead = rHead.Next
	}
	for rHead.Next != nil {
		head = head.Next
		rHead = rHead.Next
	}
	return head
}

func main() {
	lNode := &ListNode{1, &ListNode{2, nil}}
	fmt.Println(getKthFromEnd(lNode, 1))
}
